<script setup lang="ts">
import { ref } from "vue";
import ReCol from "@/components/ReCol";
import { formRules } from "./utils/rule";
import { FormProps } from "./utils/types";
import { usePublicHooks } from './hooks'
import IconSelect from '@/components/ReIcon/src/Select.vue'

const props = withDefaults(defineProps<FormProps>(), {
    formInline: () => ({
        higherDeptOptions: [],
        parentId: 0,
        name: "",
        pageUrl: "",
        code: "",
        apiUrl: "",
        icon: "",
        sort: 0,
        status: 1,
        type: 1
    })
});

const ruleFormRef = ref();
const { switchStyle } = usePublicHooks();
const newFormInline = ref(props.formInline);

function getRef() {
    return ruleFormRef.value;
}

defineExpose({ getRef });
</script>

<template>
    <el-form ref="ruleFormRef" :model="newFormInline" :rules="formRules" label-width="82px">
        <el-row :gutter="30">
            <re-col>
                <el-form-item label="上级菜单">
                    <el-cascader class="w-full" v-model="newFormInline.parentId"
                        :options="newFormInline.higherDeptOptions" :props="{
                            value: 'Id',
                            label: 'Name',
                            emitPath: false,
                            checkStrictly: true
                        }" filterable placeholder="请选择上级菜单">
                    </el-cascader>
                </el-form-item>
            </re-col>
            <re-col :value="12" :xs="24" :sm="24">
                <el-form-item label="菜单名称" prop="name">
                    <el-input v-model="newFormInline.name" clearable placeholder="请输入菜单名称" />
                </el-form-item>
            </re-col>
            <re-col :value="12" :xs="24" :sm="24">
                <el-form-item label="菜单地址" prop="pageUrl">
                    <el-input v-model="newFormInline.pageUrl" clearable placeholder="请输入菜单地址" />
                </el-form-item>
            </re-col>
            <re-col :value="12" :xs="24" :sm="24">
                <el-form-item label="菜单编号" prop="code">
                    <el-input v-model="newFormInline.code" clearable placeholder="请输入菜单编号" />
                </el-form-item>
            </re-col>
            <re-col :value="12" :xs="24" :sm="24">
                <el-form-item label="前端地址" prop="apiUrl">
                    <el-input v-model="newFormInline.apiUrl" clearable placeholder="请输入前端地址" />
                </el-form-item>
            </re-col>
            <re-col :value="12" :xs="24" :sm="24">
                <el-form-item label="显示图标">
                    <IconSelect v-model="newFormInline.icon" />
                </el-form-item>
            </re-col>
            <re-col :value="12" :xs="24" :sm="24">
                <el-form-item label="显示排序" prop="sort">
                    <el-input-number v-model="newFormInline.sort" :min="0" :max="9999" controls-position="right" />
                </el-form-item>
            </re-col>
            <re-col :value="12" :xs="24" :sm="24">
                <el-form-item label="状态" prop="status">
                    <el-switch v-model="newFormInline.status" inline-prompt :active-value="1" :inactive-value="0"
                        active-text="启用" inactive-text="停用" :style="switchStyle" />
                </el-form-item>
            </re-col>
            <re-col :value="12" :xs="24" :sm="24">
                <el-form-item label="类型" prop="type">
                    <el-radio-group v-model="newFormInline.type">
                        <el-radio :label="1">系统</el-radio>
                        <el-radio :label="2">目录</el-radio>
                        <el-radio :label="3">页面</el-radio>
                        <el-radio :label="4">功能</el-radio>
                    </el-radio-group>
                </el-form-item>
            </re-col>
        </el-row>
    </el-form>
</template>

<style lang="scss" scoped>
.el-radio {
    margin-right: 16px;
}
</style>
